package com.sjy.project.ent.api;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.sjy.framework.aspectj.lang.annotation.Log;
import com.sjy.framework.aspectj.lang.enums.BusinessType;
import com.sjy.project.ent.yearSta.domain.EntKpiYearSta;
import com.sjy.project.ent.yearSta.domain.TEntAssess;
import com.sjy.project.ent.yearSta.service.ITEntAssessService;
import com.sjy.project.system.dept.domain.Dept;
import com.sjy.project.system.dept.service.IDeptService;
import com.sjy.project.system.user.domain.User;
import com.sjy.project.system.user.service.IUserService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import com.sjy.framework.web.controller.BaseController;
import com.sjy.framework.web.domain.AjaxResult;
import com.sjy.common.constant.UserContext;
import com.sjy.common.entity.SecuryUserDetail;
import com.sjy.common.result.BaseResponse;
import com.sjy.common.utils.poi.ExcelUtil;
import com.sjy.framework.web.page.TableDataInfo;

/**
 * 企业评价视图Controller
 * 
 * @author ljb
 * @date 2022-07-09
 */
@RestController
@Api(value = "亩均评价相关接口", tags = { "亩均接口" })
@RequestMapping("/api/ent/assess")
public class ApiEntAssessController extends BaseController {
	@Autowired
	private ITEntAssessService tEntAssessService;
	@Autowired
	private IUserService userService;
	@Autowired
	private IDeptService deptService;

	@ApiOperation(value = "401、企业根据token获取评价清单", position = 403, notes = "")
//  @ApiImplicitParams({
//  })
	@PostMapping({ "/getAssessByToken" })
	public ResponseEntity<BaseResponse<TableDataInfo<TEntAssess>>> getAssessByToken() {
		SecuryUserDetail tokenUser = UserContext.getUserSession();
		if (tokenUser == null) {
			return BaseResponse.generateBadResponseEntity("用户信息无效!", null);
		}
		TEntAssess entity = new TEntAssess();
		entity.setCreditCode(tokenUser.getLoginName());
		startPage();
		List<TEntAssess> list = tEntAssessService.selectTEntAssessList(entity);
		return BaseResponse.generateOKResponseEntity(getDataTable(list));
	}

	@ApiOperation(value = "501、街道获取企业评价清单", position = 501, notes = "当前页:pageNum,分页大小：pageSize,排序字段：orderByColumn，排序方式：asc")
//  @ApiImplicitParams({
//  })
	@PostMapping({ "/list" })
	public ResponseEntity<BaseResponse<TableDataInfo<TEntAssess>>> list(TEntAssess entity) {
		SecuryUserDetail tokenUser = UserContext.getUserSession();
		User user = userService.selectUserById(tokenUser.getUserId());
		List<Dept> depts = deptService.selectStreetDepts(user.getDeptId());
		if (depts == null || depts.size() == 0) {
			return BaseResponse.generateOKResponseEntity(getDataTable(null));
		}
		if (depts.size() == 1) {
			entity.setTown(depts.get(0).getDeptName());
		}
		startPage();
		List<TEntAssess> list = tEntAssessService.selectTEntAssessList(entity);
		return BaseResponse.generateOKResponseEntity(getDataTable(list));
	}
}
